//
// create by wuhao
//

#ifndef ZKDATABASE_LOG
#define ZKDATABASE_LOG

#include <vector>
#include <string>
#include "../../consensus/include/tk_elog.h"
#include "../../consensus/include/tk_command.h"
#include "../../zookeeperServer/include/dataTree.h"
#include "../../zookeeperServer/include/serverCnxn.h"
#include "../../config/config.h"
#include "../../serialization/include/tk_jute.h"

using namespace std;

struct readBuff{
    int64_t len;
    int64_t position;
    char* buff;
    vector<string> fileName;
};
//store data tree
bool writeDataTreeToFile(dataTree * zoo_dataTree);
bool writeDataNodeToFile(dataNode * node,int fd);

bool writeServerCnxnToFile(serverCnxnFactory * cnxnFactory);
bool readServerCnxnFromFile(serverCnxnFactory * cnxnFactory);

bool readDataTreeFromFile(dataTree * zoo_dataTree);
//store log
bool writeInstanceToFile(struct tk_instance * instance,int64_t zxid);
bool writeStateToFile(struct tk_instance * instance,int64_t zxid);
vector<int32_t> readInstanceMatrixFromFile(struct tk_instance *** InstanceMatrix,int32_t groupSize);

//bool snapshot(Replica * r);

//struct readBuff readInstanceFromFile(int32_t snapshotZxid);
//bool append(int32_t replicaId,struct tk_instance ti);
//uint32_t Checksum(unsigned char *data, int32_t len);
//bool readNextLogFile(struct readBuff* rb);
int file_size2(string filename);
//int32_t nextInstance(struct tk_instance* pi,struct readBuff* rb);

//serialize instance
//void serializeInstance(struct tk_instance pi,struct serializeBuff* oa);

#endif
